package com.yanyu.space.common.sleuth.util;

import org.springframework.cloud.sleuth.Span;
import org.springframework.cloud.sleuth.brave.bridge.BraveSpan;
import org.springframework.cloud.sleuth.docs.AssertingSpan;
import org.springframework.web.server.ServerWebExchange;

/**
 * @author yanyu
 */
public class TracerFluxUtil {

    protected static final String TRACE_REQUEST_ATTR = Span.class.getName();

    public static brave.Span getSpanInRequest(ServerWebExchange exchange) {
        AssertingSpan assertingSpan = exchange.getAttribute(TRACE_REQUEST_ATTR);
        return BraveSpan.toBrave(assertingSpan.getDelegate());
    }
}
